home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earkit / mail / thor / thor231u.lha / rexx / bbsread / ParseGrabs.br
Text File  |  1996-02-04  |  5KB  |  188 lines

  1. /*
  2. ** $VER: ParseGrabs.br 1.2 (3.1.95)
  3. **
  4. ** ParseGrabs.br will check for any grabs in the download directory and
  5. ** parse them.  If there are active events which have not been deleted it
  6. ** will list these events and then ask the user whether to delete them or
  7. ** not.
  8. **
  9. ** Requires C:List, C:Delete, C:Ask and C:Resident to be present.
  10. **
  11. ** Set makeresident to 1 below for some extra speed.
  12. **
  13. ** 
  14. ** Todo:  Close window after parsing if fromthor = 1. HOW?!?
  15. **        Parse grabs in chronological order (ie check date)
  16. **
  17. ** 1.2 (3.1.96)
  18. ** ~~~~~~~~~~~~~
  19. ** Fixed: Assumed upload and downloadpaths ended with ':' or '/'
  20. **
  21. */
  22.  
  23. options results
  24.  
  25. signal on break_c
  26. signal on error
  27. signal on halt
  28.  
  29. pubscreen    = "Workbench"        /* Public screen to open progressbars on
  30.                                      if run from Shell */
  31. makeresident = 1                  /* Make list resident before starting.
  32.                                      0 = FALSE, 1 = TRUE */
  33. remresident  = 1                  /* Remove list from resident list after
  34.                                      finishing. 0 = FALSE, 1 = TRUE */
  35.  
  36. tiopen = 0; glopen = 0
  37.  
  38. EDB_DELETED       = 0    /* Event is deleted */
  39. EDB_DONE          = 2    /* Event is done */
  40. EDB_ERROR         = 3    /* Error performing this event */
  41. EDB_FREEZE        = 5    /* Event is frozen. Will not be done as long as this flag is set. */
  42.  
  43. /* See if I'm run from Thor */
  44.  
  45. if left(address(), 5) = 'THOR.' then do
  46.     thorport = address()
  47.     address(thorport)
  48.     GETGLOBALCONFIG STEM globcfg
  49.     if rc ~= 0 then call displayerror(0)
  50.     pubscreen = globcfg.PUBSCREENNAME
  51.     LOCKGUI
  52.     fromthor = 1
  53.     end
  54. else fromthor = 0
  55.  
  56. /* Open BBSREAD ARexx port */
  57.  
  58. if ~show('p', 'BBSREAD') then do; address command; "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"; "WaitForPort BBSREAD"; end
  59.  
  60. /* Find Thor's path */
  61.  
  62. call open(pn, 'ENV:Thor/THORPATH', 'R')
  63. thorpath = readln(pn)
  64. call close(pn)
  65.  
  66. /* Fetch some needed info from bbsread */
  67.  
  68. address(bbsread)
  69. GETGLOBALDATA globdata
  70. if rc ~= 0 then call displayerror(1)
  71.  
  72. GETBBSLIST bbslist
  73. if rc ~= 0 then call displayerror(1)
  74.  
  75. if makeresident = 1 then do
  76.     address(command)
  77.     'Resident C:List PURE'
  78.     end
  79.  
  80. if bbslist.COUNT > 0 then do i = 1 to bbslist.COUNT
  81.     address(bbsread)
  82.     GETBBSDATA '"'bbslist.i'"' bbsdata
  83.     if rc ~= 0 then call displayerror(1)
  84.  
  85.     if bbsdata.DNLOADPATH ~= '' then dlpath = bbsdata.DNLOADPATH
  86.     else dlpath = globdata.DNLOADPATH
  87.     if right(dlpath, 1) ~= '/' & right(dlpath, 1) ~= ':' then dlpath = dlpath'/'
  88.  
  89.     address(command)
  90.     'List >T:GrabList 'dlpath || bbsdata.GRABNAME'#? LFORMAT "%s"'
  91.  
  92.     if exists("T:GrabList") then do
  93.         glopen = open(gl, "T:GrabList", 'R')
  94.         do until eof(gl)
  95.             entry = readln(gl)
  96.             if entry ~= '' then do
  97.                 if fromthor = 0 then say '1B'x'[1mParsing 'bbsdata.BBSTYPE' grab from 'bbsdata.NAME': "'dlpath || entry'"' || '1B'x'[0m'
  98.  
  99.                 if bbsdata.NUMEVENTS > 0 then do
  100.                     if fromthor = 0 then do
  101.                         say 'There are active events on "'bbsdata.NAME'":'
  102.                         thorpath'bin/ListEvents "'bbsdata.NAME'" FULL'
  103.                         signal off error
  104.                         'Ask "*NDelete these events? [y/N]"'
  105.                         signal on error
  106.                         if rc = 5 then delevents = 1
  107.                         end
  108.                     else do
  109.                         address(thorport)
  110.                         REQUESTNOTIFY '"There are 'bbsdata.NUMEVENTS' active events on\n'bbsdata.NAME'. Delete them?"' '"Yes|No"'
  111.                         if result = 1 then delevents = 1
  112.                         end
  113.  
  114.                     if delevents = 1 then do
  115.                         address(bbsread)
  116.                         do e = bbsdata.FIRSTEVENT to bbsdata.LASTEVENT
  117.                             drop eventdata.
  118.                             READBREVENT '"'bbsdata.NAME'"' EVENTNR e DATASTEM eventdata
  119.                             if rc ~= 0 then call displayerror(0)
  120.                             if ~bittst(eventdata.FLAGS, EDB_DELETED) & ~bittst(eventdata.FLAGS, EDB_ERROR) & ~bittst(eventdata.FLAGS, EDB_DONE) & ~bittst(eventdata.FLAGS, EDB_FREEZE) then do
  121.                                 UPDATEBREVENT BBSNAME '"'bbsdata.NAME'"' EVENTNR e SETDONE
  122.                                 if rc ~= 0 then call displayerror(0)
  123.                                 end
  124.                             end
  125.                         PACKDATAFILE BBSNAME '"'bbsdata.NAME'"' EVENTDATA SHOWPROGRESS
  126.                         if rc ~= 0 then call displayerror(0)
  127.  
  128.                         GETBBSDATA '"'bbslist.i'"' bbsdata
  129.                         if rc ~= 0 then call displayerror(0)
  130.  
  131.                         address(command)
  132.                         if bbsdata.UPLOADPATH ~= '' then ulpath = bbsdata.UPLOADPATH
  133.                         else ulpath = globdata.UPLOADPATH
  134.                         if right(ulpath, 1) ~= '/' & right(ulpath, 1) ~= ':' then ulpath = ulpath'/'
  135.                         if exists(ulpath||bbsdata.REPLYPACKET) then do
  136.                             'Delete "'ulpath||bbsdata.REPLYPACKET'" QUIET FORCE'
  137.                             end
  138.                         end
  139.                     end
  140.  
  141.                 address(command)
  142.                 thorpath'bin/CfgType >T:TypeInfo 'bbsdata.BBSTYPE
  143.  
  144.                 tiopen = open(ti, "T:TypeInfo", 'R')
  145.                 tmp = readln(ti); tmp = readln(ti); tmp = readln(ti); tmp = readln(ti)
  146.                 parser = subword(tmp, 4); parser = left(parser, index(parser, ',') - 1)
  147.                 call close(ti)
  148.  
  149.                 thorpath || parser' "'bbsdata.NAME'" "'dlpath || entry'" ARCHIVE DELETE PUBSCREEN "'pubscreen'"'
  150.                 end
  151.             end
  152.         call close(gl)
  153.         end
  154.     end
  155.  
  156. break_c:
  157. error:
  158. halt:
  159.  
  160. if fromthor = 1 then do
  161.     address(thorport)
  162.     UNLOCKGUI
  163.     RESCAN
  164.     end
  165.  
  166. address(command)
  167. if glopen then call close(gl)
  168. if exists("T:GrabList") then 'Delete "T:GrabList" QUIET'
  169. if tiopen then call close(ti)
  170. if exists("T:TypeInfo") then 'Delete "T:TypeInfo" QUIET'
  171. if remresident = 1 then 'Resident LIST REMOVE'
  172.  
  173. exit(0)
  174.  
  175.  
  176. displayerror: procedure expose thorport BBSREAD.LASTERROR fromthor
  177.               parse arg finito
  178.  
  179. if fromthor = 0 then say BBSREAD.LASTERROR
  180. else do
  181.     address(thorport)
  182.     REQUESTNOTIFY '"'BBSREAD.LASTERROR'"' '"I see"'
  183.     address(bbsread)
  184.     end
  185.  
  186. if finito = 1 then signal break_c
  187. return
  188.